CC = gcc
SRCS = $(wildcard src/*.c)
OBJS = $(patsubst src/%.c, build/%.o, $(SRCS))
CFLAGS = -std=gnu11 -Wall
LDFLAG = -lmount -lext2fs
TARGET = build/xxx-ext4
TARGET_DEBUG = build/xxx-debug

all: pre-build release

pre-build:
	mkdir -p build

debug: TARGET = $(TARGET_DEBUG)
debug: CFLAGS +=  -g
debug: LDFLAG +=  -g
debug: $(TARGET)

release: $(TARGET)
	$(CC) -o build/xxx-ext4-pkexec src/wrapper/pkexec_main.c

$(TARGET):$(OBJS)
	$(CC) -o $(TARGET) $(OBJS) $(LDFLAG) 

build/%.o:src/%.c
	$(CC) -o $@ -c $< $(CFLAGS)

install:
	cat doc/readme.txt
	apt-get install xdotool
	mkdir -p /opt/xxx-ext4/
	mkdir -p /usr/share/deepin/dde-file-manager/oem-menuextensions
	cp $(TARGET) /opt/xxx-ext4/
	cp build/xxx-ext4-pkexec /opt/xxx-ext4/
	cp doc/readme.txt /opt/xxx-ext4/
	cp doc/xxx-ext4.desktop  /usr/share/deepin/dde-file-manager/oem-menuextensions
	chmod 775 /opt/xxx-ext4/xxx-ext4 
	ln -s /opt/xxx-ext4/xxx-ext4 /usr/bin/xxx-ext4
	cat doc/readme.txt

uninstall:
	rm /usr/bin/xxx-ext4
	rm /opt/xxx-ext4/ -r
	rm /usr/share/deepin/dde-file-manager/oem-menuextensions/xxx-ext4.desktop
	
clean:
	rm -rf $(TARGET) $(OBJS)
